package com.main.ok.guahaouser;

import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.io.HessianRemoteObject;

import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by kai on 2015/8/11 0011.
 * 给hessina添加http报文头
 */
public class HessianProxyWtihContextFactory extends HessianProxyFactory {

    private Map<String, String> context = new HashMap<String, String>();

    public Map<String, String> getContext() {
        return context;
    }

    public String putContext(String key, String value) {
        return context.put(key, value);
    }

    @Override
    public Object create(Class<?> api, String urlName, ClassLoader loader) throws MalformedURLException {
        HessianProxyWithContext hessianProxyWithContext = new HessianProxyWithContext(new URL(urlName), this, api);
        hessianProxyWithContext.setContext(context);
        return Proxy.newProxyInstance(loader, new Class[]{api, HessianRemoteObject.class}, hessianProxyWithContext);
    }


}
